package com.itheima.a01Functioalm;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class a01Funcionaldemo2 {
    public static void main(String[] args) {
        //创建集合
        ArrayList<String> list = new ArrayList<>();
        //添加数据
        Collections.addAll(list,"张无忌,15","周芷若,25","赵敏,13","张强,20","张三丰,100","张翠三,40");
        //封装成Student对象并添加到list集合中
        list.stream().map(new Function<String, Student>() {
            @Override
            public Student apply(String s) {
                String[] arr = s.split(",");
                String name=arr[0];
                int age = Integer.parseInt(arr[1]);
                return new Student(name,age);
            }
        }).forEach(s-> System.out.println(s));

        //使用方法引用
        List<Student> newlist = list.stream().map(Student::new).collect(Collectors.toList());
        System.out.println(newlist);
    }
}
